var exec = require('child_process').exec;
var localIp = require('./utils.js').ip;


// arguments const
var __port = 8080;
var __imageName = 'cluster_script';
var __cmd_pattern =
	// 'docker run -ti ' +
	'docker run -d ' +
	'-p 2181 -p 2888 -p 3888 ' +
	'--name node$order $imageName ' +
	'/bin/bash -c "/usr/bin/node /tmp/reg_cli.js server=$ip order=$order &" ';


var cmd_pattern = __cmd_pattern.replace('$imageName', __imageName);
cmd_pattern = cmd_pattern.replace('$ip', localIp + ":" + __port);

startNode(1);
// startNode(2);
// startNode(3);

function startNode(index) {
	var cmd_node = cmd_pattern.replace('$order', index);
	console.log(cmd_node);
	exec(cmd_node, function(error, stdout, stderr) {
		console.log('node' + index + ' started');
	});
}